package com.a2.appa3.ui.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2017/8/4.
 * Activity基类
 * 构造基本逻辑与添加常用方法
 * 未绑定presenter
 */

public abstract class BaseActivitySimple extends AppCompatActivity {
    private Unbinder unbinder;

    //    public CiticDialog.CustomDialog lottieDialog;
    public List<Disposable> disposableList;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setContentView());
        unbinder = ButterKnife.bind(this);
        ButterKnife.setDebug(true);
        initView();
    }

    @Override
    protected void onResume() {
        super.onResume();
        //TODO 添加功能
    }

    @Override
    protected void onPause() {
        super.onPause();
        //TODO 移除功能
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
//        lottieDialog.onDestroy();
//        lottieDialog = null;
    }

    /**
     * 初始化控件
     */
    private void initView() {
        //Dialog初始化
//        lottieDialog = new CiticDialog().createLottieDialog(this);

        //将id未back的控件添加返回点击事件
//        View backView = findViewById(R.id.back);
//        if (backView != null) {
//            backView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    BaseActivitySimple.this.onBackPressed();//当id为back控件点击时触发onBackPressed
//                }
//            });
//        }
    }

    /**
     * 获取DisposableList
     *
     * @return disposableList
     */
    public List<Disposable> getDisposableList() {
        if (disposableList == null) disposableList = new ArrayList<>();
        return disposableList;
    }


    /**
     * @return 默认SharedPreferences
     */
    public SharedPreferences getSharedPreferences() {
        return getSharedPreferences("", MODE_PRIVATE);
    }

    /**
     * 关闭软键盘
     *
     * @param view getWindowToken()
     */
    protected void closeKeyboard(@NonNull View view) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

    /**
     * 设置contentView
     *
     * @return
     */
    protected abstract int setContentView();
}
